<template>
	<div>
		<AplidForm ref="formRef" v-bind="BaseFormConfig" v-model="formModel" @submit="onSubmit" @reset="back">
			<template #staffNameForm="{ row }">
				<remoteSelect
					class="w-100"
					:filterable="true"
					:disabled="true"
					:paramsObj="{ creditCode }"
					api="view_dpFoundationPractitioners_page"
					filterKey="practitionersName"
					filterLabel="practitionersName"
					placeholder="请选择"
					v-model="formModel.staffName"
					@change="handleGetProjectInfo"
				></remoteSelect>
			</template>
		</AplidForm>
	</div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { ElMessageBox } from 'element-plus'
import apiMod from '@/apiMod'
import { uploadType } from '@/utils/util'
import remoteSelect from '@/components/AplidCrud/src/AplidRemote/index'
import { getStore } from '@/utils/store'
const emit = defineEmits(['refresh', 'back'])

type Props = {
	newData?: any
}
let props = withDefaults(defineProps<Props>(), {
	newData: {},
})
// 获取当前用户的统一信用代码
let creditCode = ref('')
creditCode.value = getStore('userInfo').organizationId

let formModel: any = ref({})
formModel.value = props.newData
let formRef = ref()

let BaseFormConfig = {
	inline: false,
	labelPosition: 'left',
	labelWidth: 170,
	column: [
    {
				type: 'DividerHtml',
				modelValue: '员工信息',
				labelPosition: 'top',
				span: 24,
			},
			{ label: '员工姓名', prop: 'staffName', span: 12, disabled:true, rules: [{ required: true, message: '请选择员工姓名' }] },
			{ label: '身份证号', prop: 'idCard', disabled:true, span: 12, rules: [{ required: true, message: '请填写身份证号' }] },
        //     {
		// 	label: '性别',
		// 	prop: 'gender',
		// 	propName:'genderLabel',
		// 	code:'GENDER',
		// 	api:'getDictItemList',
		// 	type:'remoteSelect',
		// 	rules: [{ required: true, message: '请选择员工性别' }],
		// 	span: 12,
		// },
			{
				label: '联系方式',
				prop: 'staffPhone',
				disabled:true,
				span: 12,
				rules: [{ required: true, message: '请填写联系方式' }],
			},
			{
				type: 'DividerHtml',
				modelValue: '入职信息',
				labelPosition: 'top',
				span: 24,
			},
	
			{
				label: '入职时间',
				prop: 'entryDate',
				type: 'date',
				format: 'YYYY年MM月DD ',
				valueFormat: 'YYYY-MM-DD',
				span: 12,
				rules: [{ required: true, message: '请选择入职时间' }],
			},
			{
				label: '岗位类型',
				prop: 'postType',
				propName: 'postTypeLabel',
				type: 'remoteSelect',
				disabled:true,
				api: 'getDictItemList',
				code: 'POSITION_TYPE',
				span: 12,
				rules: [{ required: true, message: '请选择岗位类型' }],
			},
			{
				label: '职业类型',
				prop: 'jobType',
				propName: 'jobTypeLabel',
				type: 'remoteSelect',
				disabled:true,
				api: 'getDictItemList',
				code: 'OCCUPATION_TYPE',
				span: 12,
        multiple: true,
				rules: [{ required: true, message: '请选择职业类型' }],
			},
			{
				label: '聘用方式',
				prop: 'hireMode',
				propName: 'hireModeLabel',
				type: 'remoteSelect',
				api: 'getDictItemList',
				code: 'HIRE_MODE',
				span: 12,
				rules: [{ required: true, message: '请选择聘用方式' }],
			},
			{
				label: '合同到期时间',
				prop: 'contractExpirationDate',
				type: 'date',
				format: 'YYYY年MM月DD ',
				valueFormat: 'YYYY-MM-DD',
				span: 12,
				rules: [{ required: true, message: '请选择合同到期时间' }],
			},
			{
				label: '入职协议（劳动合同）',
				prop: 'laborContract',
				type: 'upload',
				fileType: uploadType.fileMetaType,
				// listType: 'text',
				labelPosition: 'top',
				showFileList: true,
				limit: 4,
				multiple: true,
				span: 24,
				rules: [{ required: true, message: '请上传入职协议（劳动合同）' }],
			},
		]
}

const handleGetProjectInfo = (item) => {
	formModel.value.idCard = item.idCard
	formModel.value.creditCode = creditCode.value
	formModel.value.practitionersName = item.practitionersName
	formModel.value.staffPhone = item.phone
	formModel.value.postType = item.positionType
	formModel.value.postTypeLabel = item.positionTypeLabel
	formModel.value.jobType = item.occupationType
	formModel.value.jobTypeLabel = item.occupationTypeLabel
    formModel.value.gender = item.gender
	formModel.value.genderLabel = item.genderLabel
	formModel.value.belongUnit = item.unitName
	formModel.value.certificateType = item.certificateType
	formModel.value.certificateTypeLabel = item.certificateTypeLabel
}
const onSubmit = (form, done) => {
	apiMod
		.view_staff_edit(form)
		.then((res) => {
			done()
			emit('refresh')
		})
		.catch(() => {
			done()
		})
}
const back = () => {
	emit('back')
}

const onSave = () => {
	formRef.value!.onSubmit()
}
defineExpose({
	onSave,
})
</script>

<style scoped></style>
